/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package resoursePlan.impl;

import java.util.Collection;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;

import org.eclipse.emf.common.util.EList;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.emf.ecore.impl.EObjectImpl;

import org.eclipse.emf.ecore.util.EObjectContainmentEList;
import org.eclipse.emf.ecore.util.InternalEList;

import resoursePlan.ResoursePlanPackage;
import resoursePlan.Role;
import resoursePlan.RoleAssignment;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Role</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link resoursePlan.impl.RoleImpl#getTitle <em>Title</em>}</li>
 *   <li>{@link resoursePlan.impl.RoleImpl#getCompetencyRequirement <em>Competency Requirement</em>}</li>
 *   <li>{@link resoursePlan.impl.RoleImpl#getWorkload <em>Workload</em>}</li>
 *   <li>{@link resoursePlan.impl.RoleImpl#getAssignments <em>Assignments</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class RoleImpl extends EObjectImpl implements Role {
	/**
	 * The default value of the '{@link #getTitle() <em>Title</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getTitle()
	 * @generated
	 * @ordered
	 */
	protected static final String TITLE_EDEFAULT = null;

	/**
	 * The cached value of the '{@link #getTitle() <em>Title</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getTitle()
	 * @generated
	 * @ordered
	 */
	protected String title = TITLE_EDEFAULT;

	/**
	 * The default value of the '{@link #getCompetencyRequirement() <em>Competency Requirement</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getCompetencyRequirement()
	 * @generated
	 * @ordered
	 */
	protected static final String COMPETENCY_REQUIREMENT_EDEFAULT = null;

	/**
	 * The cached value of the '{@link #getCompetencyRequirement() <em>Competency Requirement</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getCompetencyRequirement()
	 * @generated
	 * @ordered
	 */
	protected String competencyRequirement = COMPETENCY_REQUIREMENT_EDEFAULT;

	/**
	 * The default value of the '{@link #getWorkload() <em>Workload</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getWorkload()
	 * @generated
	 * @ordered
	 */
	protected static final int WORKLOAD_EDEFAULT = 0;

	/**
	 * The cached value of the '{@link #getWorkload() <em>Workload</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getWorkload()
	 * @generated
	 * @ordered
	 */
	protected int workload = WORKLOAD_EDEFAULT;

	/**
	 * The cached value of the '{@link #getAssignments() <em>Assignments</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getAssignments()
	 * @generated
	 * @ordered
	 */
	protected EList<RoleAssignment> assignments;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected RoleImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return ResoursePlanPackage.Literals.ROLE;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public String getTitle() {
		return title;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setTitle(String newTitle) {
		String oldTitle = title;
		title = newTitle;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, ResoursePlanPackage.ROLE__TITLE, oldTitle, title));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public String getCompetencyRequirement() {
		return competencyRequirement;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setCompetencyRequirement(String newCompetencyRequirement) {
		String oldCompetencyRequirement = competencyRequirement;
		competencyRequirement = newCompetencyRequirement;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, ResoursePlanPackage.ROLE__COMPETENCY_REQUIREMENT, oldCompetencyRequirement, competencyRequirement));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public int getWorkload() {
		return workload;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setWorkload(int newWorkload) {
		int oldWorkload = workload;
		workload = newWorkload;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, ResoursePlanPackage.ROLE__WORKLOAD, oldWorkload, workload));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<RoleAssignment> getAssignments() {
		if (assignments == null) {
			assignments = new EObjectContainmentEList<RoleAssignment>(RoleAssignment.class, this, ResoursePlanPackage.ROLE__ASSIGNMENTS);
		}
		return assignments;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case ResoursePlanPackage.ROLE__ASSIGNMENTS:
				return ((InternalEList<?>)getAssignments()).basicRemove(otherEnd, msgs);
		}
		return super.eInverseRemove(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case ResoursePlanPackage.ROLE__TITLE:
				return getTitle();
			case ResoursePlanPackage.ROLE__COMPETENCY_REQUIREMENT:
				return getCompetencyRequirement();
			case ResoursePlanPackage.ROLE__WORKLOAD:
				return getWorkload();
			case ResoursePlanPackage.ROLE__ASSIGNMENTS:
				return getAssignments();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@SuppressWarnings("unchecked")
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case ResoursePlanPackage.ROLE__TITLE:
				setTitle((String)newValue);
				return;
			case ResoursePlanPackage.ROLE__COMPETENCY_REQUIREMENT:
				setCompetencyRequirement((String)newValue);
				return;
			case ResoursePlanPackage.ROLE__WORKLOAD:
				setWorkload((Integer)newValue);
				return;
			case ResoursePlanPackage.ROLE__ASSIGNMENTS:
				getAssignments().clear();
				getAssignments().addAll((Collection<? extends RoleAssignment>)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case ResoursePlanPackage.ROLE__TITLE:
				setTitle(TITLE_EDEFAULT);
				return;
			case ResoursePlanPackage.ROLE__COMPETENCY_REQUIREMENT:
				setCompetencyRequirement(COMPETENCY_REQUIREMENT_EDEFAULT);
				return;
			case ResoursePlanPackage.ROLE__WORKLOAD:
				setWorkload(WORKLOAD_EDEFAULT);
				return;
			case ResoursePlanPackage.ROLE__ASSIGNMENTS:
				getAssignments().clear();
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case ResoursePlanPackage.ROLE__TITLE:
				return TITLE_EDEFAULT == null ? title != null : !TITLE_EDEFAULT.equals(title);
			case ResoursePlanPackage.ROLE__COMPETENCY_REQUIREMENT:
				return COMPETENCY_REQUIREMENT_EDEFAULT == null ? competencyRequirement != null : !COMPETENCY_REQUIREMENT_EDEFAULT.equals(competencyRequirement);
			case ResoursePlanPackage.ROLE__WORKLOAD:
				return workload != WORKLOAD_EDEFAULT;
			case ResoursePlanPackage.ROLE__ASSIGNMENTS:
				return assignments != null && !assignments.isEmpty();
		}
		return super.eIsSet(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public String toString() {
		if (eIsProxy()) return super.toString();

		StringBuffer result = new StringBuffer(super.toString());
		result.append(" (title: ");
		result.append(title);
		result.append(", competencyRequirement: ");
		result.append(competencyRequirement);
		result.append(", workload: ");
		result.append(workload);
		result.append(')');
		return result.toString();
	}

} //RoleImpl
